<template>
	<view>
		<view class="hb_bg">
			<!-- <image v-show="isShow" src="https://img.jinghushi.com/images/9/2024/12/QNVuGuuq2nX9c4LXk0kV4mnh2lHuM6.png"></image> -->
			<image src="https://img.jinghushi.com/images/9/2025/01/rt9MhACm99WPTuuP3A3OPZWDbD96M3.png"></image>
		</view>
		<view v-show="isShow" class="q_btn" @click="openhb">
			<image src="https://img.jinghushi.com/images/9/2025/01/iLSZUE4RUS4RHArMd4HriIuHu4lAIt.png"></image>
		</view>
		<view class="hb_info">
			<view class="flex_center">
				<image :src="info.avatar"></image>
				<view>{{info.nickname}}的红包</view>
			</view>
			<view class="hb_con" v-show="!isShow">{{text}}</view>
			<view class="hb_con" v-show="isShow">{{info.title}}</view>
		</view>
		<view v-show="!isShow" class="hb_obsolete" @click="$navTo('/pages/user/hbdetail?id='+info.id)">查看领取详情 ></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mid: 0,
				id: 0,
				isLogin: false,
				isShow: true,
				text: '',
				info: []
			}
		},
		onLoad(options){
			this.id = options.id;
			if (options.scene) {
				let scene = decodeURIComponent(options.scene);
				this.mid = this.gup('mid', scene);
			}
			if(options.mid){
				this.mid = options.mid;
			}
			this.getInfo();
			if(!uni.getStorageSync('token')){
				this.getToken();
			}else{
				this.isLogin = true;
			}
		},
		methods: {
			openhb(){
				if(this.isLogin){
					console.log('已登录');
					this.$axios('redpacket/receive','POST','member',{
						id: this.id
					}).then(res=>{
						if(res.data.code == 200){
							this.isShow = true;
							this.$navTo('/pages/user/hbdetail?id='+this.id)
						}else{
							this.isShow = false;
							this.text = res.data.data;
						}
					})
				}else{
					console.log('未登录');
				}
			},
			getToken(){
				// #ifdef MP-WEIXIN
				uni.login({
					provider: 'weixin',
					success:res=> {
						this.$axios('login/autologin','POST','member',{
							mid: this.mid,
							code: res.code
						}).then(res=>{
							if(res.data.code == 200){
								uni.setStorageSync('token', res.data.data);
								uni.setStorageSync('Jh_recotabshops', 1);
								this.isLogin = true;
							}
						})
					}
				})
				// #endif
				// #ifdef MP-ALIPAY
				my.getAuthCode({
				    scopes: 'auth_base',
				    success: res => {
						this.$axios('login/autologinAliPay','POST','member',{
							mid: this.mid,
							code: res.authCode
						}).then(res=>{
							if(res.data.code == 200){
								uni.setStorageSync('token', res.data.data);
								uni.setStorageSync('Jh_recotabshops', 1);
								this.isLogin = true;
							}
						})
					}
				})
				// #endif
			},
			getInfo(){
				this.$axios('redpacket/getRedpacket','POST','member',{
					id: this.id
				}).then(res=>{
					if(res.data.code == 200){
						this.info = res.data.data.info;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.hb_bg{
	position: fixed;
	left: 0;
	right: 0;
	margin: auto;
	width: 524rpx;
	height: 858rpx;
	top: 160rpx;
	box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.1);
	image{
		width: 100%;
		height: 100%;
	}
}
.hb_info{
	width: 524rpx;
	margin: 300rpx auto 0;
	color: #fbd7a6;
	position: absolute;
	top: 330rpx;
	left: 0;
	right: 0;
	margin: auto;
	padding: 0 30rpx;
	image{
		width: 40rpx;
		height: 40rpx;
		border-radius: 6rpx;
		margin-right: 10rpx;
		flex-shrink: 0;
	}
	.flex_center{
		font-size: 24rpx;
	}
	.hb_con{
		margin-top: 14rpx;
		text-align: center;
		font-size: 32rpx;
	}
}
.q_btn{
	width: 200rpx;
	height: 200rpx;
	// border: 2rpx solid #fff;
	margin: 758rpx auto 0;
	position: relative;
	image{
		width: 100%;
		height: 100%;
	}
}
.hb_obsolete{
	position: absolute;
	font-size: 24rpx;
	color: #fbd7a6;
	text-align: center;
	left: 0;
	right: 0;
	top: 920rpx;
}
</style>
